home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Skeleton / UDocumentSkeleton.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  7.3 KB  |  217 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UDocumentSkeleton.cp
  3. // Copyright © 1991-96 by Apple Computer, Inc. All rights reserved. 
  4. //----------------------------------------------------------------------------------------
  5.  
  6. /*
  7.     Changes
  8.          3/21/96    srf        The "SquareDots" parameter of IStdPrintHandler is obsolete
  9. */
  10.  
  11. #ifndef __UDOCUMENTSKELETON__
  12. #include "UDocumentSkeleton.h"
  13. #endif
  14.  
  15. // Skeleton
  16.  
  17. #ifndef __UCOMMANDSKELETON__
  18. #include "UCommandSkeleton.h"
  19. #endif
  20.  
  21. #ifndef __UVIEWSKELETON__
  22. #include "UViewSkeleton.h"
  23. #endif
  24.  
  25. // MacApp
  26.  
  27. #ifndef __UMACAPPGLOBALS__
  28. #include "UMacAppGlobals.h"
  29. #endif
  30.  
  31. #ifndef __UMENUMGR__
  32. #include "UMenuMgr.h"
  33. #endif
  34.  
  35. #ifndef __UPRINTING__
  36. #include "UPrinting.h"
  37. #endif
  38.  
  39. #ifndef __UVIEWSERVER__
  40. #include "UViewServer.h"
  41. #endif
  42.  
  43. #ifndef __UWINDOW__
  44. #include "UWindow.h"
  45. #endif
  46.  
  47. //----------------------------------------------------------------------------------------
  48. // Constants:
  49.  
  50. const ResNumber kSkeletonWindowID = kDefaultWindowID;
  51.  
  52. //========================================================================================
  53. // CLASS TDocumentSkeleton
  54. //========================================================================================
  55. #undef Inherited
  56. #define Inherited TFileBasedDocument
  57.  
  58. #pragma segment AOpen
  59. MA_DEFINE_CLASS_M1(TDocumentSkeleton, Inherited);
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // TDocumentSkeleton constructor 
  63. //----------------------------------------------------------------------------------------
  64. #pragma segment AOpen
  65.  
  66. TDocumentSkeleton::TDocumentSkeleton()  
  67. {
  68. } // TDocumentSkeleton::TDocumentSkeleton 
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // TDocumentSkeleton::IDocumentSkeleton: 
  72. //----------------------------------------------------------------------------------------
  73. #pragma segment AOpen
  74.         
  75. void TDocumentSkeleton::IDocumentSkeleton(TFile* itsFile,
  76.                                           OSType itsCreator)
  77. {
  78.     this->IFileBasedDocument(itsFile,itsCreator);
  79. } // TDocumentSkeleton::IDocumentSkeleton 
  80.  
  81. //----------------------------------------------------------------------------------------
  82. // TDocumentSkeleton destructor
  83. //----------------------------------------------------------------------------------------
  84. #pragma segment AClose
  85.  
  86. TDocumentSkeleton::~TDocumentSkeleton()
  87. {
  88. }
  89.  
  90. //----------------------------------------------------------------------------------------
  91. // TDocumentSkeleton::FreeData: 
  92. //----------------------------------------------------------------------------------------
  93. #pragma segment AClose
  94.  
  95. void TDocumentSkeleton::FreeData() // Override 
  96. {
  97.     Inherited::FreeData();
  98. } // TDocumentSkeleton::FreeData 
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // TDocumentSkeleton::DoInitialState: 
  102. //----------------------------------------------------------------------------------------
  103. #pragma segment AOpen
  104.  
  105. void TDocumentSkeleton::DoInitialState() // Override 
  106. {
  107.     Inherited::DoInitialState();
  108. } // TDocumentSkeleton::DoInitialState 
  109.  
  110. //----------------------------------------------------------------------------------------
  111. // TDocumentSkeleton::DoMakeViews: 
  112. //----------------------------------------------------------------------------------------
  113. #pragma segment AOpen
  114.  
  115. void TDocumentSkeleton::DoMakeViews(Boolean /*forPrinting*/) // Override 
  116. {
  117.     TWindow* aWindow = NULL;
  118.     TStdPrintHandler* aHandler = NULL;
  119.     TViewSkeleton* aViewSkeleton = NULL;
  120.  
  121.     FailNIL(aWindow = gViewServer->NewTemplateWindow(kSkeletonWindowID, this));
  122.  
  123.     aViewSkeleton = (TViewSkeleton*) (aWindow->FindSubView('SKEL'));    // Must cast because FindSubView returns TView
  124.  
  125.     aHandler = new TStdPrintHandler;
  126.     aHandler->IStdPrintHandler(this,            // its document 
  127.                                aViewSkeleton,    // its view 
  128.                                kFixedSize,        // horzontal page size is fixed 
  129.                                kFixedSize);        // vertical page size is fixed 
  130. } // TDocumentSkeleton::DoMakeViews 
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // TDocumentSkeleton::DoNeedDiskSpace: 
  134. //----------------------------------------------------------------------------------------
  135. #pragma segment AWriteFile
  136.  
  137. void TDocumentSkeleton::DoNeedDiskSpace(TFile* itsFile,
  138.                                         long& dataForkBytes,
  139.                                         long& rsrcForkBytes) // Override 
  140. {
  141.     Inherited::DoNeedDiskSpace(itsFile, dataForkBytes, rsrcForkBytes);
  142. } // TDocumentSkeleton::DoNeedDiskSpace 
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // TDocumentSkeleton::DoMenuCommand: This method is overridden to handle menu items which
  146. // are enabled when this document is in the target chain. In this example, this is true
  147. // when the document is open and its window is the active window. The inherited method
  148. // should always be called so that MacApp can allow successor objects in the target chain
  149. // (i.e. the application) to handle THEIR menu items.
  150. //----------------------------------------------------------------------------------------
  151. #pragma segment ASelCommand
  152.  
  153. void TDocumentSkeleton::DoMenuCommand(CommandNumber aCommandNumber) // Override 
  154. {
  155.     switch (aCommandNumber) 
  156.     {
  157.         case cCommandHandledByDocument: 
  158.             {
  159.                 TCommandSkeleton* aCommand = new TCommandSkeleton;
  160.                 aCommand->ICommandSkeleton(aCommandNumber, this);
  161.                 this->PostCommand(aCommand);
  162.             }
  163.             break;
  164.         default:
  165.             Inherited::DoMenuCommand(aCommandNumber);
  166.             break;
  167.     }
  168. } // TDocumentSkeleton::DoMenuCommand 
  169.  
  170. //----------------------------------------------------------------------------------------
  171. // TDocumentSkeleton::DoRead: 
  172. //----------------------------------------------------------------------------------------
  173. #pragma segment AReadFile
  174.  
  175. void TDocumentSkeleton::DoRead(TFile* aFile,
  176.                                        Boolean forPrinting) // Override 
  177. {
  178.     Inherited::DoRead(aFile,forPrinting);
  179. } // TDocumentSkeleton::DoRead 
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // TDocumentSkeleton::DoSetupMenus: This method is overridden to enable menu items which
  183. // should be enabled when this object is in the target chain. MacApp initially disables
  184. // all menu items, then lets the objects in the target chain enable those items they
  185. // handle.
  186. //
  187. // A document object is in the target chain when its window is the active window.
  188. //
  189. // The inherited method is called so that TDocument can enable document-level menu items
  190. // like "Save ". This also ensures that objects further up the target chain (the
  191. // application) can set up THEIR menus.
  192. //----------------------------------------------------------------------------------------
  193. #pragma segment ARes
  194.  
  195. void TDocumentSkeleton::DoSetupMenus() // Override 
  196. {
  197.     Inherited::DoSetupMenus();
  198.     
  199.     Enable(cCommandHandledByDocument,TRUE);
  200. } // TDocumentSkeleton::DoSetupMenus 
  201.  
  202. //----------------------------------------------------------------------------------------
  203. // TDocumentSkeleton::DoWrite: 
  204. //----------------------------------------------------------------------------------------
  205. #pragma segment AWriteFile
  206.  
  207. void TDocumentSkeleton::DoWrite(TFile* aFile,
  208.                                     Boolean makingCopy) // Override 
  209. {
  210.     Inherited::DoWrite(aFile,makingCopy);
  211. } // TDocumentSkeleton::DoWrite 
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // End of UDocumentSkeleton.cp
  215.  
  216. #pragma segment Inline
  217.